#pragma once

#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

template <typename T>
inline void debug_shm (char const *key, T *A, int ndims, ...)
{
	shm_array_t A_size, *A_shm;
	A_size.type = shm_array_type_map<T>::type;


	va_list ap;
	va_start (ap, ndims);

	int N = 1;
	A_size.ndims = ndims;	
	for (int i = 0; i < ndims; ++i){
		A_size.dims[i] = va_arg (ap, int);

		N = N * A_size.dims[i];
		std::cerr << ", " << A_size.dims[i];
	}
	std::cerr << ") ... " << std::flush;

	make_shm_array (key, &A_size, &A_shm);

	memcpy (A_shm->data.c, A, sizeof(*A)*N);

	put_shm_array  (key, A_shm);

	std::cerr << "Wrote shm_array(\"" << key << "\", " << N << " " 
		      << shm_type_strings[A_size.type] << "s)" << std::endl;
}

